package uml.behavioral.state.forum;

/**
 * 状态模式--环境类<br>
 * on 2023/1/6 14:32
 */
public class ForumUser {
    private int integration;//用户积分
    private UserState state;
    private String userName;//用户名
    private boolean sysInfoClosed = false;//是否关闭系统消息

    public int getIntegration() {
        return integration;
    }

    public void setIntegration(int integration) {
        this.integration = integration;
    }

    /**
     * 关闭系统消息
     *
     * @param closeSysInfo true，关闭;false，开启
     */
    public void closeSysInfo(boolean closeSysInfo) {
        this.sysInfoClosed = closeSysInfo;
    }

    public boolean isClosed() {
        return sysInfoClosed;
    }

    public String getUserName() {
        return userName;
    }

    /**
     * 积分<100:初级<br>
     * 100=<积分<1000:高级<br>
     * 积分>=1000:专家<br>
     *
     * @param userName           用户名
     * @param initialIntegration 初始积分
     */
    public ForumUser(String userName, int initialIntegration) {
        this.userName = userName;
        this.integration = initialIntegration;
        //根据积分创建初始不同状态
        if (integration < 100) {
            state = new PrimaryState(this);
        } else if (integration >= 100 && integration < 1000) {
            state = new SeniorState(this);
        } else if (integration >= 1000) {
            state = new ProfessionalState(this);
        }
    }

    public void setState(UserState state) {
        this.state = state;
    }

    public void commit(String msg) {
        state.commit(msg);
        System.out.println(userName + "拥有积分:" + integration);
        System.out.println("----------------------------------------------------------");
    }

    public void reply(String msg) {
        state.reply(msg);
        System.out.println(userName + "拥有积分:" + integration);
        System.out.println("----------------------------------------------------------");
    }

    public void fileDownload(String fileName) {
        state.fileDownload(fileName);
        System.out.println(userName + "拥有积分:" + integration);
        System.out.println("----------------------------------------------------------");
    }
}
